package oceanwiki.job;

import oceanwiki.service.IDocService;
import oceanwiki.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @FileName DocJob
 * @Description
 * @Author Me
 * @date 2024-09-19
 **/

@Component
public class DocJob {
    private static final Logger LOG = LoggerFactory.getLogger(DocJob.class);

    @Autowired
    private IDocService docService;
    @Autowired
    private SnowFlake snowFlake;

    //每隔30s更新书籍信息
    @Scheduled(cron = "5/30 * * * * ?")
    public void cron() {
        //增加日志流水号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        LOG.info("更新电子书籍文档数据开始");
        long start = System.currentTimeMillis();
        docService.updateEbookInfo();
        LOG.info("更新结束，耗时：{}ms", System.currentTimeMillis() - start);
    }

}
